Fix theoretical memory leak in tpo.
authorrobertlipe <robertlipe@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Sun, 29 Mar 2015 04:45:46 +0000 (04:45 +0000)
committerrobertlipe <robertlipe@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Sun, 29 Mar 2015 04:45:46 +0000 (04:45 +0000)
Fix missing va_end in gpsserial (which matters on no modern arch)
Fix actual copy/paste bug in ggv_ovl.

gpsbabel/ggv_ovl.cc
gpsbabel/jeeps/gpsserial.cc
gpsbabel/tpo.cc

index da45bcdc3e9e51320d746a9d618aa99116fb3d83..36171c445be923c6791729bf9dde044a9d7d457f 100644 (file)
@@ -137,11 +137,11 @@ ggv_ovl_read(void)
         if (group > 1) {
           route_add_head(rte);
           route_ct++;
-            trk->rte_name = QString("Route %1").arg(route_ct);
+          rte->rte_name = QString("Route %1").arg(route_ct);
         } else {
           track_add_head(trk);
           track_ct++;
-            trk->rte_name = QString("Track %1").arg(track_ct);
+          trk->rte_name = QString("Track %1").arg(track_ct);
         }
 
         for (j = 0; j < points; j++) {
index 0300779820e4bed8daf731c7e0254e6725353f7b..e510f540cfaca968676e9dbb9eed44e2b0b218db 100644 (file)
@@ -396,6 +396,7 @@ void GPS_Serial_Error(const char* mb, ...)
 //                     GetLastError(), 0, s, sizeof(msg) - b - 2, 0 );
   strcat(msg, strerror(errno));
   GPS_Error(msg);
+  va_end(ap);
 }
 
 int32 GPS_Serial_Read(gpsdevh* dh, void* ibuf, int size)
index 13816f67c2d09fa66e77d82164e9603419122ace..90060fe57d2f62e14952cbadab441f0bf99a84da 100644 (file)
@@ -77,6 +77,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <vector>
+#include <QtCore/QScopedArrayPointer> // Wish we could use c++11...
 
 #define MYNAME "TPO"
 
@@ -491,7 +492,15 @@ Waypoint* tpo_convert_ll(int lat, int lon)
 }
 
 #define TRACKNAMELENGTH 256
-struct style_info {
+class StyleInfo {
+public:
+  StyleInfo() {
+    name[0] = 0;
+    color[0] = 0;
+    color[1] = 0;
+    color[2] = 0;
+    wide = dash = 0;
+  }
   char name[TRACKNAMELENGTH]; // some huge value
   uint8_t color[3];  // keep R/G/B values separate because line_color needs BGR
   uint8_t wide;
@@ -506,7 +515,7 @@ void tpo_process_tracks(void)
   unsigned int track_count, track_style_count;
   unsigned int xx,ii,tmp;
 
-  int DEBUG=0;
+  const int DEBUG = 0;
 
   if (DEBUG) {
     printf("Processing Track Styles... (added in 2012 by SRE)\n");
@@ -523,7 +532,7 @@ void tpo_process_tracks(void)
     printf("Unpacking %d track styles...\n",track_style_count);
   }
 
-  style_info* styles = (style_info*)xcalloc(track_style_count, sizeof(style_info));
+  QScopedArrayPointer<StyleInfo> styles(new StyleInfo[track_style_count]);
 
   for (ii = 0; ii < track_style_count; ii++) {
 
@@ -787,8 +796,6 @@ void tpo_process_tracks(void)
 
     xfree(buf);
   }
-  xfree(styles);
-//printf("\n");
 }